package stu.hxl.mpdemo.dao.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import com.baomidou.mybatisplus.extension.handlers.FastjsonTypeHandler;
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import stu.hxl.mpdemo.enums.UserTypeEnum;
import stu.hxl.mpdemo.enums.VipTypeEnum;

import java.util.List;

/**
 * @author sharloon
 * @date 2019/11/18
 */
@Data
@Accessors(chain = true)
@TableName(autoResultMap = true)
@NoArgsConstructor
public class User extends Model<User> {

    @TableId(type = IdType.AUTO)
    private Long id;

    private String name;

    private Integer age;

    private String email;

    private UserTypeEnum userType;

    private VipTypeEnum vipType;


    /**
     * 注意！！！
     * <p>
     * 1. 必须开启映射注解: @TableName(autoResultMap = true)
     * <p>
     * 2. 以下两种类型处理器,二选一也可以同时存在(JacksonTypeHandler 、 FastjsonTypeHandler)
     * <p>
     * 3. 选择对应的json处理器也必须存在对应依赖包,详见pom文件
     * <p>
     * 4. 数据库中的json属性对应的实体中的字段可以是对象或者List
     * <p>
     * 5. 如果查询出来的json数据有中文乱码问题，请升级mysql-connector-java的版本为5.1.40或以上
     */
    @TableField(typeHandler = FastjsonTypeHandler.class)
    private List<OtherInfo> otherInfo;

    @TableField(typeHandler = JacksonTypeHandler.class)
    private Wallet wallet;

    public User(String name, Integer age, String email, UserTypeEnum userType, VipTypeEnum vipType) {
        this.name = name;
        this.age = age;
        this.email = email;
        this.userType = userType;
        this.vipType = vipType;
    }

    public User(String name, Integer age, String email, List<OtherInfo> otherInfo) {
        this.name = name;
        this.age = age;
        this.email = email;
        this.otherInfo = otherInfo;
    }
}
